Global Const MIDIERR_UNPREPARED = (MIDIERR_BASE + 0) ' header not prepared
Global Const MIDIERR_STILLPLAYING = (MIDIERR_BASE + 1) ' still something playing
Global Const MIDIERR_NOMAP = (MIDIERR_BASE + 2) ' no current map
Global Const MIDIERR_NOTREADY = (MIDIERR_BASE + 3) ' hardware is still busy
Global Const MIDIERR_NODEVICE = (MIDIERR_BASE + 4) ' port no longer connected
Global Const MIDIERR_INVALIDSETUP = (MIDIERR_BASE + 5) ' invalid setup
Global Const MIDIERR_LASTERROR = (MIDIERR_BASE + 5) ' last error in range
Global Const MIDIPATCHSIZE = 128
' MIDI callback messages
Global Const MIM_OPEN = MM_MIM_OPEN
Global Const MIM_CLOSE = MM_MIM_CLOSE
Global Const MIM_DATA = MM_MIM_DATA
Global Const MIM_LONGDATA = MM_MIM_LONGDATA
Global Const MIM_ERROR = MM_MIM_ERROR
Global Const MIM_LONGERROR = MM_MIM_LONGERROR
Global Const MOM_OPEN = MM_MOM_OPEN
Global Const MOM_CLOSE = MM_MOM_CLOSE
Global Const MOM_DONE = MM_MOM_DONE
' device ID for MIDI mapper
Global Const MIDIMAPPER = (-1)
Global Const MIDI_MAPPER = (-1)
' flags for wFlags parm of midiOutCachePatches(), midiOutCacheDrumPatches()
Global Const MIDI_CACHE_ALL = 1
Global Const MIDI_CACHE_BESTFIT = 2
Global Const MIDI_CACHE_QUERY = 3
Global Const MIDI_UNCACHE = 4
' MIDI output device capabilities structure
Type MIDIOUTCAPS
wMid As Integer ' manufacturer ID
wPid As Integer ' product ID
vDriverVersion As Integer ' version of the driver
szPname As String * MAXPNAMELEN ' product name (NULL terminated string)
wTechnology As Integer ' type of device
wVoices As Integer ' # of voices (internal synth only)
wNotes As Integer ' max # of notes (internal synth only)
wChannelMask As Integer ' channels used (internal synth only)
dwSupport As Long ' functionality supported by driver
End Type
' flags for wTechnology field of MIDIOUTCAPS structure
Global Const MOD_MIDIPORT = 1 ' output port
Global Const MOD_SYNTH = 2 ' generic internal synth
Global Const MOD_SQSYNTH = 3 ' square wave internal synth
Global Const MOD_FMSYNTH = 4 ' FM internal synth
Global Const MOD_MAPPER = 5 ' MIDI mapper
' flags for dwSupport field of MIDIOUTCAPS structure
Global Const MIDICAPS_VOLUME = &H1 ' supports volume control
Global Const MIDICAPS_LRVOLUME = &H2 ' separate left-right volume control
Global Const MIDICAPS_CACHE = &H4
' MIDI output device capabilities structure
Type MIDIINCAPS
wMid As Integer ' manufacturer ID
wPid As Integer ' product ID
vDriverVersion As Integer ' version of the driver
szPname As String * MAXPNAMELEN ' product name (NULL terminated string)
End Type
' MIDI data block header
Type MIDIHDR
lpData As Long ' pointer to locked data block
dwBufferLength As Long ' length of data in data block
dwBytesRecorded As Long ' used for input only
dwUser As Long ' for client's use
dwFlags As Long ' assorted flags (see defines)
midihdr_tag As Long ' reserved for driver
reserved As Long ' reserved for driver
End Type
' flags for dwFlags field of MIDIHDR structure
Global Const MHDR_DONE = &H1 ' done bit
Global Const MHDR_PREPARED = &H2 ' set if header prepared
Global Const MHDR_INQUEUE = &H4 ' reserved for driver
' MIDI function prototypes
Declare Function midiOutGetNumDevs Lib "MMSYSTEM" () As Integer
Declare Function midiOutGetDevCaps Lib "MMSYSTEM" (ByVal udeviceid As Integer, lpCaps As MIDIOUTCAPS, ByVal uSize As Integer) As Integer
Declare Function midiOutGetVolume Lib "MMSYSTEM" (ByVal udeviceid As Integer, lpdwvolume As Long) As Integer
Declare Function midiOutSetVolume Lib "MMSYSTEM" (ByVal udeviceid As Integer, ByVal dwVolume As Long) As Integer
Declare Function midiOutGetErrorText Lib "MMSYSTEM" (ByVal uError As Integer, ByVal lpText As String, ByVal uSize As Integer) As Integer
Declare Function midiOutOpen Lib "MMSYSTEM" (lphMidiOut As Integer, ByVal udeviceid As Integer, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Integer
Declare Function midiOutClose Lib "MMSYSTEM" (ByVal hmidiout As Integer) As Integer
Declare Function midiOutPrepareHeader Lib "MMSYSTEM" (ByVal hmidiout As Integer, lphMidiOut As MIDIHDR, ByVal uSize As Integer) As Integer
Declare Function midiOutUnprepareHeader Lib "MMSYSTEM" (ByVal hmidiout As Integer, lphMidiOut As MIDIHDR, ByVal uSize As Integer) As Integer
Declare Function midiOutShortMsg Lib "MMSYSTEM" (ByVal hmidiout As Integer, ByVal dwMsg As Long) As Integer
Declare Function midiOutLongMsg Lib "MMSYSTEM" (ByVal hmidiout As Integer, lphMidiOut As MIDIHDR, ByVal uSize As Integer) As Integer
Declare Function midiOutReset Lib "MMSYSTEM" (ByVal hmidiout As Integer) As Integer
Declare Function midiOutCachePatches Lib "MMSYSTEM" (ByVal hmidiout As Integer, ByVal uBank As Integer, ByVal PatchArray As Long, ByVal uFlags As Integer) As Integer
Declare Function midiOutCacheDrumPatches Lib "MMSYSTEM" (ByVal hmidiout As Integer, ByVal uPatch As Integer, lpwKeyArray As Integer, ByVal uFlags As Integer) As Integer
Declare Function midiOutGetID Lib "MMSYSTEM" (ByVal hmidiout As Integer, lpudeviceid As Integer) As Integer
Declare Function midiOutMessage Lib "MMSYSTEM" (ByVal hmidiout As Integer, ByVal uMessage As Integer, ByVal dw1 As Long, ByVal dw2 As Long) As Long
Declare Function midiInGetNumDevs Lib "MMSYSTEM" () As Integer
Declare Function midiInGetDevCaps Lib "MMSYSTEM" (ByVal udeviceid As Integer, lpCaps As MIDIINCAPS, ByVal uSize As Integer) As Integer
Declare Function midiInGetErrorText Lib "MMSYSTEM" (ByVal uError As Integer, ByVal lpText As String, ByVal uSize As Integer) As Integer
Declare Function midiInOpen Lib "MMSYSTEM" (lphMidiIn As Integer, ByVal udeviceid As Integer, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Integer
Declare Function midiInClose Lib "MMSYSTEM" (ByVal hMidiIn As Integer) As Integer
Declare Function midiInPrepareHeader Lib "MMSYSTEM" (ByVal hMidiIn As Integer, lpMidiInHdr As MIDIHDR, ByVal uSize As Integer) As Integer
Declare Function midiInUnprepareHeader Lib "MMSYSTEM" (ByVal hMidiIn As Integer, lpMidiInHdr As MIDIHDR, ByVal uSize As Integer) As Integer
Declare Function midiInAddBuffer Lib "MMSYSTEM" (ByVal hMidiIn As Integer, lpMidiInHdr As MIDIHDR, ByVal uSize As Integer) As Integer
Declare Function midiInStart Lib "MMSYSTEM" (ByVal hMidiIn As Integer) As Integer
Declare Function midiInStop Lib "MMSYSTEM" (ByVal hMidiIn As Integer) As Integer
Declare Function midiInReset Lib "MMSYSTEM" (ByVal hMidiIn As Integer) As Integer
Declare Function midiInGetID Lib "MMSYSTEM" (ByVal hMidiIn As Integer, lpudeviceid As Integer) As Integer
Declare Function midiInMessage Lib "MMSYSTEM" (ByVal hMidiIn As Integer, ByVal uMessage As Integer, ByVal dw1 As Long, ByVal dw2 As Long) As Long
Sub midi_listoutdevs (c As Control)
Dim i As Integer
Dim x As Integer
Dim midicaps As MIDIOUTCAPS
c.Clear
' Test for MIDI mapper
If midiOutGetDevCaps(MIDIMAPPER, midicaps, Len(midicaps)) = 0 Then ' OK
c.AddItem midicaps.szPname
c.ItemData(c.NewIndex) = MIDIMAPPER ' Save dev_id in item data
End If
' Add other devs
For i = 0 To midiOutGetNumDevs() - 1
If midiOutGetDevCaps(i, midicaps, Len(midicaps)) = 0 Then ' OK
c.AddItem midicaps.szPname
c.ItemData(c.NewIndex) = i ' Save dev_id
End If
Next
End Sub
Sub midi_out_close ()
Dim midi_error As Integer
If m_hmidiout <> 0 Then
midi_error = midiOutClose(m_hmidiout)
If Not midi_error = 0 Then
Call midi_outerr(midi_error)
End If
m_hmidiout = 0
End If
End Sub
Function midi_out_open (ByVal dev_id As Integer) As Integer